import numpy as np


class BOX:
    def __init__(self, name, x1, y1, x2, y2, x3, y3, x4, y4):
        x1, y1, x2, y2, x3, y3, x4, y4 = [int(i) for i in [x1, y1, x2, y2, x3, y3, x4, y4]]
        self.name = name
        self.poly_box = [x1, y1, x2, y2, x3, y3, x4, y4]
        self.poly2dim = np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]])
        self.xmin = min(x1, x2, x3, x4)
        self.ymin = min(y1, y2, y3, y4)
        self.xmax = max(x1, x2, x3, x4)
        self.ymax = max(y1, y2, y3, y4)
        self.width = self.xmax - self.xmin
        self.height = self.ymax - self.ymin
        self.center_x = (self.xmin + self.xmax) // 2
        self.center_y = (self.ymin + self.ymax) // 2
        self.box = [self.xmin, self.ymin, self.xmax, self.ymax]


class RecBOX(BOX):
    def __init__(self, name, xmin, ymin, xmax, ymax):
        x1, y1, x2, y2, x3, y3, x4, y4 = xmin, ymin, xmax, ymin, xmax, ymax, xmin, ymax
        super(RecBOX, self).__init__(name, x1, y1, x2, y2, x3, y3, x4, y4)


class OneImage:
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.boxes = []

    def add(self, box):
        self.boxes.append(box)
